home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / attclk2.arc / SETDATE.C < prev    next >
C/C++ Source or Header  |  1986-01-09  |  2KB  |  66 lines

  1. /* :ts=8
  2.  *
  3.  *    setdate.c
  4.  *
  5.  * Main routine for setdate program.  Accesses real time clock
  6.  * of AT&T PC 6300 to set PC-DOS date and time.
  7.  *
  8.  */
  9.  
  10. #include "setdate.h"
  11. struct tm buf;
  12.  
  13. main(argc, argv)
  14. int    argc;
  15. char    *argv[];
  16. {
  17.     int    last_sec;
  18.  
  19.         /* invoking setdate w/o parms merely displays date/time */
  20.     if (argc == 1) {
  21.             /* get current DOS date/time */
  22.         dostime(&buf);
  23.             /* display date/time */
  24.         timedisp("");
  25.     }
  26.     else
  27.             /* check for valid parms */
  28.         switch (argv[1][1]) {
  29.             /* use real time clock to set DOS date/time */
  30.           case 'r':
  31.                 /* read real time clock */
  32.             readclock();
  33.                 /* set DOS date */
  34.             bdos(0x2b, (buf.tm_mon + 1 << 8) + buf.tm_mday,
  35.                     buf.tm_year + 1900);
  36.                 /* set DOS time */
  37.             bdos(0x2d, (buf.tm_sec << 8) + buf.tm_hsec,
  38.                     (buf.tm_hour << 8) + buf.tm_min);
  39.                 /* display date used for settings */
  40.             timedisp("DOS set to ");
  41.               break;
  42.             /* use DOS date/time to set real time clock */
  43.           case 's':
  44.                 /* get current DOS date but wait */
  45.                 /* for new minute */
  46.             do {
  47.                 dostime(&buf);
  48.                 if (buf.tm_sec != last_sec) {
  49.                     printf("\rWaiting for next minute: %d:%02d:%02d",
  50.                         buf.tm_hour, buf.tm_min, buf.tm_sec);
  51.                     last_sec = buf.tm_sec;
  52.                 }
  53.             } while (buf.tm_sec != 0);
  54.             printf("\r");
  55.                 /* set real time clock using DOS values */
  56.             writeclock();
  57.                 /* display date used for settings */
  58.             timedisp("Real time clock set to ");
  59.               break;
  60.             /* unknown parameter.  display usage */
  61.           default:
  62.             printf("usage: setclock [-r] [-s]\n");
  63.               break;
  64.         }
  65. }
  66.